//
//  SYSelectClassView.m
//  SanYiTeaching
//
//  Created by 郑浩然 on 2020/3/30.
//  Copyright © 2020年 SanYi. All rights reserved.
//

#import "SYSelectClassView.h"

@interface SYSelectClassView ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) UITableView *curTableView;
@property (strong, nonatomic) NSMutableArray *dataListArr;

@end


@implementation SYSelectClassView

- (instancetype)init {
    self = [super init];
    if (self) {
        [self initSubView];
    }
    return self;
}

- (void)initSubView {
    self.dataListArr = [NSMutableArray array];
    [self addSubview:self.curTableView];
    [self.curTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.right.left.equalTo(self);
    }];
    
}
//请求数据
- (void)requestData {
    [MBProgressHUD mj_showLoading];
    __weak typeof(self) weakSelf = self;
    [SYRequestAPI fd_requestCampusListSuccess:^(NSMutableArray *listArr) {
        [MBProgressHUD mj_hideHUD];
        [weakSelf.dataListArr addObjectsFromArray:listArr];
        [weakSelf.curTableView reloadData];
        
    } fail:^(NSError *error) {
        [MBProgressHUD mj_hideHUD];
        [MBProgressHUD zr_showError:error.domain];
    }];
    
    
}



//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//    return 3;
//}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataListArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
    }
//    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = [UIFont systemFontOfSize:15];
    cell.textLabel.textColor = [UIColor colorWithHexString:@"#333333"];
    NSDictionary *dict = self.dataListArr[indexPath.row];
    cell.textLabel.text = [dict nilObjectForKey:@"campusName"];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary *dict = self.dataListArr[indexPath.row];
    NSString *campusId = [dict nilObjectForKey:@"campusId"];
    if (self.block) {
        self.block(campusId);
    }
    
}


- (UITableView *)curTableView {
    if (!_curTableView) {
        _curTableView = [[UITableView alloc] init];
        _curTableView.delegate = self;
        _curTableView.dataSource = self;
        _curTableView.tableFooterView = [UIView new];
        
    }
    return _curTableView;
}


@end
